<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */
    include 'farmwork.php';
	header("content-type:text/html;charset=utf-8");
	login();

$li1233='class="active"';
$li12333='class="active"';
?>
<?php include 'header.php';?>
    <title>代理充值-<?php echo $title?></title>
<?php include 'list.php';?>
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
<?php include 'overview.php';?>
            <div class="row">
                <div class="col-lg-12">
                    <!--work progress start-->
                    <section class="panel panel-success">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>代理充值</h1>
                                <p>代理在线充值</p>
					 <div class="panel-body">
          <form action="./daili-chong.php" method="get" class="form-inline" role="form">
			<div class="form-group">
              <label>类别</label>
              <select name="type" class="form-control">
			    <option value="1">UID</option>
                <option value="2">账号</option>
				<option value="3">QQ</option>
              </select>
            </div>
			<div class="form-group">
              <label>内容</label>
              <input type="text" name="kw" value="" class="form-control" placeholder="请输入所选择的信息">
            </div>
			<div class="form-group">
              <label>金额</label>
              <input type="text" name="dlje" value="" class="form-control" placeholder="请输入要充值的金额">
            </div>

								<div class="form-group">
                                <label for="txtDomain">所属产品</label>
                                <select name="ycp" class="form-control" >
								
 									<?php 
										$sql="select * from products ORDER BY `id` DESC";
										$result=mysqli_query($con,$sql);
										if($result&&mysqli_num_rows($result)){
											while ($row=mysqli_fetch_assoc($result)) {
											echo "<option value='".$row['cp']."'>".$row['cp']."</option>";											
											}
										}
									?>   
									</select>
								</div>	
								
            <input type="submit" name="submit" value="充值" class="btn btn-info"/> 
          </form>
        </div>
<?php
//添加卡密
$time=time();
if($_GET[submit]=="充值"){
$kw = $_GET['kw'];
	if($_GET['type']==1)
		$wenb = "id='{$kw}'";
	elseif($_GET['type']==2)
		$wenb = "domain='{$kw}'";
	elseif($_GET['type']==3)
		$wenb = "qq='{$kw}'";
	
//$dluid=$_GET[dluid];
$dlje=$_GET[dlje];
$ycp1 = $_GET[ycp];
if($kw=="" or $dlje==""){
	echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">请填写完整！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili-chong.php' });  }});</script>");
}else{
$sql = "select * from daili where ".$wenb." and ycp='$ycp1'";
//echo $sql;
	$result = mysqli_query($con,$sql);
	if($result && mysqli_num_rows($result)>0){
		$data=mysqli_fetch_array($result);
		$rmb = $data['rmb'];
		$rmb = $rmb + $dlje;
		$dluid=$data['id'];
		$sql = "UPDATE `daili` SET `rmb` = '$rmb' where id='$dluid'";
		mysqli_query($con,$sql);
		$ip = getip();
		$time1=time();
		$sql = "INSERT INTO `log_dl` (`uid`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$dluid', '$time1', '$ycp1', '+$dlje', '$rmb', '管理员充值','$ip');";//添加流水日志
		mysqli_query($con,$sql);
		echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['返回']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">充值成功！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili-chong.php' });  }});</script>");
		exit();
	}
	else{
		echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['返回']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">未找到该UID代理！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili-chong.php' });  }});</script>");
	exit();}
}}
?>
                            </div>
                        </div>						
<div class="table-responsive">
                        <table  class="display table table-bordered table-striped" id="dynamic-table">
                            <thead>
                            <tr>
                                <th>ID</th>
								<th>UID</th>
								<th>产品</th>
								<th>余额变化</th>
								<th>当前余额</th>
								<th>备注</th>
								<th>IP</th>
                                <th>时间</th>
                                
                            </tr>
                            </thead>
                            <tbody>
									<?php
 $page = $_GET["page"];
 if(isset($_POST["page"]) && $_POST["page"] != "")
    {
     $page = $_POST['page'];
     }
 if($page == ""){
     $page = 1;
     } 

 $page_size = 10; //每页多少条数据
 $_pageNum = 5; //最多显示多少个页码
 $query = "select count(bz='管理员充值') as total from log_dl";
 $result = mysqli_query($con,$query);
 $rownum = mysqli_fetch_row($result);
 $message_count = $rownum[0];

 $page_count = ceil($message_count / $page_size);
 $offset = ($page-1) * $page_size;
 $pages = $page_count;
 $_start = $page - floor($_pageNum / 2); //计算开始页
 $_start = $_start < 1 ? 1 : $_start;
 $_end = $page + floor($_pageNum / 2); //计算结束页
 $_end = $_end > $pages? $pages : $_end;

 $_curPageNum = $_end - $_start + 1;
 // 左调整
if($_curPageNum < $_pageNum && $_start > 1){
     $_start = $_start - ($_pageNum - $_curPageNum);
     $_start = $_start < 1 ? 1 : $_start;
     $_curPageNum = $_end - $_start + 1;
     }
 // 右边调整
if($_curPageNum < $_pageNum && $_end < $pages){
     $_end = $_end + ($_pageNum - $_curPageNum);
     $_end = $_end > $pages? $pages : $_end;
     }


 ?>
 									<?php 
										$sql="select * from log_dl where bz='管理员充值' order by id DESC limit $offset,$page_size";
										$result=mysqli_query($con,$sql);
										if($result&&mysqli_num_rows($result)){
											while ($row=mysqli_fetch_assoc($result)) {
											echo "<tr class='gradeX'>";
											echo "<td >".$row['id']."</td>";
											echo "<td >".$row['uid']."</td>";
											echo "<td ><span class='label label-success'>".$row['cp']."</span></td>";
											echo "<td >".$row['rmb']."</td>";
											echo "<td >".$row['zrmb']."</td>";
											echo "<td >".$row['bz']."</td>";
											echo "<td >".$row['ip']."</td>";
											echo "<td ><span class='label label-success'>".date("Y-m-d H:i:s",$row['time'])."</span></td>";

											}
										}
									?>                           
                            </tfoot>
                        </table>
						</div>
						<table  class="display table table-bordered table-striped" id="dynamic-table">
						<tfoot>
							<tr>
							<td ><ul class="pagination"><li class="disabled"><a>当前页码：<?php echo $page;?>/<?php echo $page_count;?></a></li><li class="disabled"><a>记录条数：<?php echo $message_count;?>条</a></li>
							
							<?php

if($page != 1){
     echo "<li ><a href=?page=1>首页</a></li>";
     echo "<li ><a href=?page=" . ($page-1) . ">&laquo;</a></li>";
     } else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}

for ($i = $_start; $i <= $_end; $i++){
     if($i == $page){
         $_pageHtml .= '<li ><a>' . $i . '</a></li>';
         }else{
         $_pageHtml .= '<li ><a href="' . $url . '?page=' . $i . '">' . $i . '</a></li>';
         }
     }
echo $_pageHtml;
if($page < $page_count){
     echo "<li ><a href=?page=" . ($page + 1) . ">&raquo;</a></li>";
     echo "<li ><a href=?page=" . $page_count . ">尾页</a></li>";
     } else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}	 
echo'</ul></td>';
?>
						
							</tr>
							</tfoot>
							</table>
                    </section>
                    <!--work progress end-->
                </div></div>

        </section>
    </section>
    <!--main content end-->

<?php include 'footer.php';?>
